package com.bwie.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bwie.mapper.TbOrderMapper;
import com.bwie.pojo.TbGroup;
import com.bwie.pojo.TbOrder;
import com.bwie.service.TbGroupService;
import com.bwie.mapper.TbGroupMapper;
import com.bwie.utils.R;
import com.bwie.utils.TokenUtil;
import com.bwie.vo.GroupVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
* @author Lenovo
* @description 针对表【tb_group_record(用户参团表)】的数据库操作Service实现
* @createDate 2025-07-26 13:54:22
*/
@Service
public class TbGroupServiceImpl extends ServiceImpl<TbGroupMapper, TbGroup>
    implements TbGroupService {

    @Autowired
    TbGroupMapper tbGroupMapper;
    @Autowired
    HttpServletRequest request;
    @Autowired
    TbOrderMapper tbOrderMapper;

    @Override
    public R getGroupList(GroupVo groupVo) {
        Page<TbGroup> page = new Page<>(groupVo.getPageNum(), groupVo.getPageSize());

        Page<TbGroup> tbGroupPage = tbGroupMapper.getGroupList(page, groupVo);
        return R.OK(tbGroupPage);
    }

    @Override
    public R getOrderListById() {
        String token = request.getHeader("token");
        if (token == null) {
            return R.ERROR(500, "请先登录");
        }

        Integer userId = TokenUtil.userId(token);

        List<TbOrder> list= tbOrderMapper.getOrderListById(userId);

        return R.OK(list);

    }

    @Override
    public R deleteOrder(TbOrder tbOrder) {
        TbOrder order = tbOrderMapper.selectById(tbOrder.getOrderId());
        if(order==null){
            return R.ERROR(500,"订单不存在");
        }
        tbOrderMapper.deleteById(tbOrder.getOrderId());
        return R.OK();

    }
}




